import datetime
from fastapi.responses import Response
from fastapi import APIRouter, Depends, Query
from sqlalchemy.orm import Session
from core.response import resp_200, resp_400

from app.monitor_doris.handlers.monitor_doris_http_record_handler import MonitorDorisHttpRecordHandler
from app.monitor_doris.handlers.monitor_doris_service_handler import MonitorDorisServiceHandler
from common.database import get_db
from core.security import permission_checker
from app.monitor_doris.schemas import *
from setting import config

router = APIRouter()


#### prometheus的metrics ####
@router.get('/http/metrics/', summary="获取http的metrics格式信息", description="监控-doris")
async def get_monitor_doris_http_metrics(db: Session = Depends(get_db)):
    monitor_doris_http_record_handler = MonitorDorisHttpRecordHandler()
    result = monitor_doris_http_record_handler.get_http_all_metrics(db)
    if not result:
        message = "get monitor http metrics failed"
        logger.error(message)
        return resp_400(message)
    return Response(content=result, media_type="text/plain") 


@router.get('/service/metrics/', summary="获取doris的metrics格式信息", description="监控-doris")
async def get_monitor_doris_service_metrics(db: Session = Depends(get_db)):
    monitor_doris_service_handler = MonitorDorisServiceHandler()
    result = monitor_doris_service_handler.get_doris_service_metrics(db)
    if not result:
        message = "get monitor service metrics failed"
        logger.error(message)
        return resp_400(message)
    return Response(content=result, media_type="text/plain") 